82B - Sets - CodeForces Solution


constructive algorithms hashing implementation *1700

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define ll long long
#define nl '\n'
using namespace std;

void sol() {
    ll n;
    cin >> n;
    vector<vector<ll>> v(n * (n - 1) / 2);
    for (int i = 0; i < n * (n - 1) / 2; ++i) {
        ll k;
        cin >> k;
        v[i].resize(k);
        for (ll j = 0; j < k; ++j){
            cin >> v[i][j];
        }
    }
    if (n == 2) {
        cout << "1 " << v[0][0] << "\n";
        cout << (ll)v[0].size() - 1 << " ";
        for (ll i = 1; i < (ll)v[0].size(); ++i){
            cout << v[0][i] << " ";
        }
        return ;
    }
    unordered_map<ll, vector<ll>> x;
    map<vector<ll>, vector<ll>> y;
    for (int i = 0; i < n * (n - 1) / 2; ++i) {
        for (auto z : v[i]) x[z].push_back(i);
    }
    for (auto p : x) y[p.second].push_back(p.first);
    for (auto p : y) {
        cout << (ll)p.second.size() << " ";
        for (int l = 0; l < (ll)p.second.size(); ++l) cout << p.second[l] << " ";
        cout << nl;
    }

}






int main() {
    int tc = 1;
    //cin >> tc;
    while (tc--) {
        sol();
    }
    return 0;
}


Comments

Submit
0 Comments
More Questions

7A - Kalevitch and Chess
912B - New Year's Eve
1537C - Challenging Cliffs
879B - Table Tennis
1674E - Breaking the Wall
1282A - Temporarily unavailable
1366C - Palindromic Paths
336A - Vasily the Bear and Triangle
926A - 2-3-numbers
276D - Little Girl and Maximum XOR
1253C - Sweets Eating
1047A - Little C Loves 3 I
758D - Ability To Convert
733A - Grasshopper And the String
216A - Tiling with Hexagons
1351B - Square
1225A - Forgetting Things
1717A - Madoka and Strange Thoughts
1717B - Madoka and Underground Competitions
61B - Hard Work
959B - Mahmoud and Ehab and the message
802G - Fake News (easy)
1717C - Madoka and Formal Statement
420A - Start Up
1031A - Golden Plate
1559C - Mocha and Hiking
427B - Prison Transfer
330A - Cakeminator
426A - Sereja and Mugs
363A - Soroban